package com.boot2551.control;
import com.boot2551.bean.Admin;
import com.boot2551.service.AdminS;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "admin.action")
public class AdminC {
    @Resource
    public AdminS as;

    /**
     * 也可通过参数查找方法
     * @param a
     * @return
     */
    @RequestMapping(params = "one")
    @ResponseBody
//    public Map<String,Object> one(@RequestBody Admin a, HttpSession session){
    public Map<String,Object> one(Admin a, HttpSession session){
        Admin obj=as.one(a.getAname(),a.getApwd());
        Map<String,Object> data=new HashMap<>();
        if (obj!=null){
//            将数据存入session中
            session.setAttribute("ad",obj);
            data.put("r",1);
            data.put("ad",obj);
        }else{
            data.put("r",0);
            data.put("ad",null);
        }
        return data;
    }
}
